package db.view;

//Code Genarated by JGuiD
import java.awt.*;
import java.awt.event.*;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

import javax.swing.*;

public class GUISQLHtmlReport extends JFrame
{
    JLabel dburl;
     JTextField urlv;
     JLabel dbtype;
     JComboBox dbtypev;
     JLabel username;
     JTextField unamev;
     JLabel pasword;
     JTextField password;
     JButton connect;
     JButton cancel;
     public static String tdbtype,turl,tdbname,tpass,tdbprefix;
     Properties props= new Properties();
   public GUISQLHtmlReport()
   {
     getContentPane().setLayout(null);
     setupGUI();
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   }
   void setupGUI()
   {
     	dburl = new JLabel();
	dburl.setLocation(57,58);
	dburl.setSize(105,28);
	dburl.setText("DB_URL");
	dburl.setToolTipText("$DataBase Url");
	getContentPane().add(dburl);

	urlv = new JTextField();
	urlv.setLocation(230,59);
	urlv.setSize(264,25);
	urlv.setText("hostname:port/DBname");
	urlv.setColumns(10);
	getContentPane().add(urlv);

	dbtype = new JLabel();
	dbtype.setLocation(58,13);
	dbtype.setSize(102,29);
	dbtype.setText("DataBase Type");
	getContentPane().add(dbtype);

	String dbtypev_tmp[]={"Oracle","DB2","MySql"};
	dbtypev = new JComboBox(dbtypev_tmp);
		dbtypev.setLocation(231,9);
	dbtypev.setSize(122,30);
	dbtypev.setEditable(false );
	getContentPane().add(dbtypev);

	username = new JLabel();
	username.setLocation(57,104);
	username.setSize(104,27);
	username.setText("Uusername");
	username.setToolTipText("$Database username");
	getContentPane().add(username);

	unamev = new JTextField();
	unamev.setLocation(230,99);
	unamev.setSize(147,27);
	unamev.setText("username");
	//unamev.setRows(5);
	unamev.setColumns(5);
	getContentPane().add(unamev);

	pasword = new JLabel();
	pasword.setLocation(57,145);
	pasword.setSize(103,31);
	pasword.setText("Password");
	pasword.setToolTipText("$Database Password");
	getContentPane().add(pasword);

	password = new JTextField();
	password.setLocation(228,148);
	password.setSize(150,28);
	password.setText("Password");
	//password.setRows(5);
	password.setColumns(5);
	password.setToolTipText("$Database password");
	getContentPane().add(password);

	connect = new JButton();
	connect.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent arg0) {
			tdbtype=dbtypev.getSelectedItem().toString();
			tdbname=unamev.getText();
			tpass=password.getText();
			turl=urlv.getText();
			if(tdbtype.equals("Oracle"))
			{
				tdbprefix="jdbc:oracle:thin:@//";
			}
			else	if(tdbtype.equals("DB2"))
			{
				tdbprefix="jdbc:db2://";
			}
			else	if(tdbtype.equals("MySql"))
			{
				tdbprefix="jdbc:mysql://";
			}
			System.out.println(tdbtype+turl+"\n"+tdbname+tpass);
			props.setProperty("UserName", tdbname);
			props.setProperty("Password", tpass);
			props.setProperty("DBURL", tdbprefix+turl);
			try {
				props.store(new FileOutputStream("db.properties"), null);
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			setVisible(false);
			new sqleditor();
		}
	});
	connect.setLocation(104,205);
	connect.setSize(100,39);
	connect.setText("Connect");
	connect.setToolTipText("$Click to Connect ");
	getContentPane().add(connect);

	cancel = new JButton();
	cancel.setLocation(251,205);
	cancel.setSize(104,39);
	cancel.setText("Cancel");
	getContentPane().add(cancel);

	setTitle("GUISQLHtmlReport");
	setSize(562,328);
	setVisible(true);
	setResizable(true);
	
	
   }
    public static void main( String args[] )
   {
     new GUISQLHtmlReport();
   }
}  
